package com.ruoyi.system.wnjk.producer;

import com.ruoyi.system.wnjk.config.RefundMQConfig;
import com.ruoyi.system.wnjk.domain.po.RefundMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 普通队列，退款使用
 */
@Service
public class RefundProducer {

    private final RabbitTemplate rabbitTemplate;

    @Autowired
    public RefundProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     *  向队列 发送退款消息
     * @param orderId 订单id
     * @param orderType 来源模块
     * @param tradeNo 支付宝交易号
     * @param reason 退款原因
     * @param amount 退款金额
     */
    public void sendRefundRequest(String orderId,String orderType, String tradeNo,String reason, String amount) {
        RefundMessage message = new RefundMessage(orderId,orderType,tradeNo,reason,amount);
        rabbitTemplate.convertAndSend(RefundMQConfig.REFUND_EXCHANGE, RefundMQConfig.REFUND_QUEUE, message);
//        System.out.println(" [x] Sent refund request for order: " + orderId);
    }
}
